import java.lang.reflect.*;
import java.net.*;
import java.io.*;

public class ListenerThread extends Thread {
   public void run() {
      try {
         ServerSocket server = new ServerSocket(Launcher.socketPort);
         while (true) {
            System.out.println("about to wait");
            Socket socket = server.accept();   
            System.out.println("opened socket from client");
            InputStream iStream = socket.getInputStream();
            int length = iStream.read();
            byte[] bytes = new byte[length];
            iStream.read(bytes);
            String className = new String(bytes);
            Launcher.go(className);
         }
      } catch (IOException e) {
         e.printStackTrace();
         System.out.println("Failed to start");
      }
   }
}
